package game.resources;


import game.resources.History.historyEntry;

import java.sql.Date;
import java.util.List;


public class Profile {

    final static int initialRating = 1000;
    long userID;
	String firstName;
	String lastName;
	History history;
	int rating;
	boolean dirty;
	int addedHistory;
	
	public Profile(long userID,String firstName,String lastName,int rating) {
		this.userID = userID;
		this.firstName = firstName;
		this.lastName = lastName;
		this.rating = rating;
		history = new History();
		dirty = false;
		addedHistory = 0;
	}
	
	public Profile(long userID,String firstName,String lastName) {
		this(userID,firstName,lastName,initialRating);
	}

	public long getUserID() {
		return userID;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
		dirty = true;
	}

	public String getFirstName() {
		return firstName;
	}
	
	public void setLastName(String lastName) {
		this.lastName = lastName;
		dirty = true;
	}

	public String getLastName() {
		return lastName;
	}
	
	public String getFullName() {
		return getFirstName() + " " + getLastName();
	}

	public History getHistory() {
		return history;
	}

	public int getRating() {
		return rating;
	}
	
	public void setRating(int rating) {
		this.rating = rating;
		dirty = true;
	}
	
//	public void increaseRating(int amount) {
//		rating += amount;
//		dirty = true;
//	}
//	
//	public void decreaseRating(int amount) {
//		rating -= amount;
//		dirty = true;
//	}
	
	public boolean isDirty() {
		return dirty;
	}
	
	public History getAddedHistories() {
		History result = new History();
		for (int i=addedHistory;i>0;i--) {
			historyEntry entry = getHistory().getEntry(getHistory().getNumOfHistories()-i);
			result.addEntry(entry);
		}
		return result;
	}
	
	public void resetDirtyBits() {
		dirty = false;
		addedHistory = 0;
	}
	
	public void addHistoryEntry(Date date, List<String> rivals, int score) {
		getHistory().addEntry(date, rivals, score);
		addedHistory++;
	}
	
	public String toString() {
	    return this.getFirstName();
	}
}
